package effects;

import loadsave.Memento;
import loadsave.loadsaveobject.Iterator;
import loadsave.loadsaveobject.LoadSaveObject;
import loadsave.loadsaveobject.LoadSaveObjectComposite;
import loadsave.loadsaveobject.LoadSavePrimitive;
import map.Direction;
import stat.EntityStatList;
import stat.StatList;
import visitors.EffectsVisitor;

public class RiverEffect extends Effect {
	private int force;
	private Direction direction;
	
	/**
	 * Empty Constructor
	 */
	public RiverEffect() {
		super();
	}
	
	/**
	 * Parameterized Constructor
	 * @param modelName
	 * Name of the model image
	 * @param force
	 * Force of the river (i.e., speed of the push)
	 * @param direction
	 * Direction of the force to push
	 */
	public RiverEffect( String modelName, int force, Direction direction ) {
		super( modelName );
		setForce( force );
		setDirection( direction );
	}
	
	/**
	 * Interface for visitor
	 */
	public void accept(EffectsVisitor ev) {
		ev.visitRiverEffect( this );
	}

	/**
	 * Clone interface
	 */
	public Effect clone() {
		return new RiverEffect( getName(), force, direction );
	}

	/**
	 * Returns EnetityStatList with stats with values of zero
	 */
	public StatList computeStats() {
		return new EntityStatList();
	}

	/**
	 * Null mutator
	 */
	public void setStats(StatList statList) {
		return;
	}

	/**
	 * Public mutator for force
	 * @param force
	 */
	public void setForce( int force ) {
		this.force = force;
	}
	
	/**
	 * public accessor for force
	 * @return
	 */
	public int getForce() {
		return force;
	}
	
	/**
	 * Public mutator for direction
	 * @param force
	 */
	public void setDirection( Direction direction ) {
		this.direction = direction;
	}
	
	/**
	 * public mutator for force
	 * @return
	 */
	public Direction getDirection() {
		return direction;
	}
	
	public Memento getMemento() {
		return new Memento() {

			public LoadSaveObject getState() {
				LoadSaveObject lso = RiverEffect.super.getMemento().getState();
				LoadSaveObjectComposite toReturn = new LoadSaveObjectComposite("", "RiverEffect");
				Iterator<LoadSaveObject> i = lso.getIterator();
				for (i.init(); i.hasNext(); i.next()) {
					toReturn.add(i.getCurrKey().getValue(), i.getCurrVal());
				}
				toReturn.add("force", new LoadSavePrimitive("force", "int", String.valueOf( force) ) );
				toReturn.add("direction", new LoadSavePrimitive("direction", "Direction", direction.toString() ) );
				return toReturn;
			}

			public void restoreState(LoadSaveObject lso) {
				RiverEffect.super.getMemento().restoreState(lso);
				force = Integer.valueOf( lso.get("force").getValue() );
				direction = Direction.valueOf( lso.get("direction").getValue() );
			}
			
		};
	}
}
